#ifndef _SESSION_MGR_ERR_H
#define _SESSION_MGR_ERR_H

#include <errno.h>
#include <stdio.h>
#include <string.h>

#include <stdexcept>
#include <string>

#define app_error(format, ...) {\
    char str[128];\
    sprintf(str, format, ## __VA_ARGS__ );\
    throw std::runtime_error(str);\
}

#define lib_err(func) {\
    char str[128];\
    throw std::runtime_error(std::string(#func) + strerror_r(errno, str, 128));\
}

#define safe_call(func, ...) {\
    int err = func( __VA_ARGS__ );\
    if(err)\
    {\
        char str[128];\
        throw std::runtime_error(std::string(#func ": ") + strerror_r(errno, str, 128));\
    }\
}

#endif
